package com.itheima.controller.backend.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class FileUploadController {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @PostMapping("/upload")
    public String uploadFile(@RequestParam("file") MultipartFile file) {
        // 假设上传成功后返回的图片 URL
        String imageUrl = "http://example.com/images/" + file.getOriginalFilename();

        // 将图片地址保存到 Redis 的 uploaded_images 集合中
        redisTemplate.opsForSet().add("uploaded_images", imageUrl);

        return "File uploaded successfully: " + imageUrl;
    }
}